<template>
  <div class="login-wrap">
    <div class="ms-title">用户注册</div>
    <div class="ms-login">
      <el-form :model="registerForm" :rules="ruleForm">
        <el-form-item label="用户名" prop="name">
          <el-input v-model="registerForm.name" placeholder="请输入用户名"/>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model="registerForm.password" placeholder="请输入密码"/>
        </el-form-item>
        <div class="login-but">
          <el-button  type="primary" @click="register">注册</el-button>
          <el-button type="info" @click="goLogin">登录</el-button>
        </div>
      </el-form>
    </div>
  </div>
</template>

<script>
import {ref,reactive,getCurrentInstance} from 'vue'
import {useRouter} from 'vue-router'
import {reqRegister} from "@/api";
import {ElMessage} from "element-plus";
export default {
name: "Register",
  setup(){
    const registerForm=reactive({})
    const ruleForm= reactive({
      name: [
        { required: true, trigger: 'blur' , message: '请输入用户名'}
      ],
      password: [
        { required: true, trigger: 'blur', message: '请输入密码' }
      ],
    })
    const router=useRouter()
    const register=async ()=>{
      const result=await reqRegister(registerForm.name,registerForm.password)
      if (result.status===10000){
        ElMessage.success('注册成功')
        await router.push('/login')
      }else {
        ElMessage.error('系统异常')
      }
    }
    const goLogin=()=>{
        router.push('/login')
    }
    return {ruleForm,registerForm,register,goLogin}
  }
}
</script>

<style scoped>
.login-wrap {
  position: relative;
  background: url("../assets/img/back.jpg") fixed center;
  background-size: cover;
  width: 100%;
  height:695px;
}
.ms-title {
  position: absolute;
  top: 50%;
  width: 100%;
  margin-top: -230px;
  text-align: center;
  font-size: 30px;
  font-weight: 600;
  color: black;
}
.ms-login{
  position:absolute;
  left: 50%;
  top: 50%;
  width: 320px;
  height: 170px;
  margin-left:-190px;
  margin-top: -150px;
  background: #fff;
  padding: 40px;
  border-radius: 5px;
}
.login-but{
  margin-top: 25px;
  display: flex;
}
.login-but button{
  width: 50%;
  height: 36px;
}
</style>
